package org.budo.beetl.resource.http;

import java.io.Reader;
import java.io.StringReader;

import org.beetl.core.Resource;
import org.beetl.core.ResourceLoader;
import org.budo.support.spring.context.aware.BudoApplicationContextAware;

/**
 * @author limingwei
 */
public class BudoHttpBeetlResource extends Resource {
    public BudoHttpBeetlResource(String id, ResourceLoader resourceLoader) {
        super(id, resourceLoader);
    }

    @Override
    public Reader openReader() {
        BudoHttpBeetlResourceLoader resourceLoader = (BudoHttpBeetlResourceLoader) this.getResourceLoader();
        String path = resourceLoader.getUrl() + this.getId();

        BudoBeetlHttpResourceClient budoBeetlHttpResourceClient = BudoApplicationContextAware.getBeanCached(BudoBeetlHttpResourceClient.class);
        String body = budoBeetlHttpResourceClient.request(path);

        return new StringReader(body);
    }

    @Override
    public boolean isModified() {
        return true;
    }
}